package yur.wedding.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import yur.wedding.modules.sys.entity.SysDocumentDirectoryrightsEntity;
import yur.wedding.modules.sys.entity.SysDocumentEntity;
import yur.wedding.modules.sys.service.SysDeptService;
import yur.wedding.modules.sys.service.SysDocumentDirectoryrightsService;
import yur.wedding.modules.sys.service.SysDocumentService;
import yur.wedding.modules.sys.service.SysRoleService;
import yur.wedding.utils.PageUtils;
import yur.wedding.utils.R;
import yur.wedding.validator.ValidatorUtils;


/**
 * 文档目录权限
 *
 * @author Yur
 * @email ${email}
 * @date 2022-08-18 07:10:16
 */
@RestController
@RequestMapping("sys/sysdocumentdirectoryrights")
public class SysDocumentDirectoryrightsController {
    @Autowired
    private SysDocumentDirectoryrightsService sysDocumentDirectoryrightsService;

    @Autowired
    protected SysRoleService sysRoleService;

    @Autowired
    protected SysDeptService sysDeptService;



    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = sysDocumentDirectoryrightsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:info")
    public R info(@PathVariable("id") Long id) {
        SysDocumentDirectoryrightsEntity sysDocumentDirectoryrights = sysDocumentDirectoryrightsService.getById(id);

        return R.ok().put("sysDocumentDirectoryrights", sysDocumentDirectoryrights);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:save")
    public R save(@RequestBody SysDocumentDirectoryrightsEntity sysDocumentDirectoryrights) {
        sysDocumentDirectoryrightsService.save(sysDocumentDirectoryrights);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:update")
    public R update(@RequestBody SysDocumentDirectoryrightsEntity sysDocumentDirectoryrights) {
        ValidatorUtils.validateEntity(sysDocumentDirectoryrights);
        sysDocumentDirectoryrightsService.updateById(sysDocumentDirectoryrights);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:delete")
    public R delete(@RequestBody Long[] ids) {


            sysDocumentDirectoryrightsService.removeByIds(Arrays.asList(ids));
            return R.ok();



    }

    /**
     * 获取所在文档下面有那些权限
     */
    @RequestMapping("/documentDirectoryrightslist/{dbgyId}")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:documentDirectoryrightslist")
    public R documentDirectoryrightslist(@PathVariable("dbgyId") Long dbgyId, @RequestParam Map<String, Object> params) {

        PageUtils page = sysDocumentDirectoryrightsService.documentDirectoryrightslist(dbgyId, params);
        return R.ok().put("page", page);
    }

    /**
     * 文档添加 权限
     *
     * @param userIdIds
     * @return
     */
    @RequestMapping("/DirecToryrigsave")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:DirecToryrigsave")
    public R DirecToryrigsave(@RequestBody String userIdIds) {

        sysDocumentDirectoryrightsService.DirecToryrigsave(userIdIds);
        return R.ok();
    }


    /**
     * 文档添加角色权限时  初始化模糊查询
     */
    @RequestMapping("/roleselectlist")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:roleselectlist")
    public R roleselectlist(@RequestParam Map<String, Object> params) {
        System.out.println("模糊条件:" + StringUtils.isNotBlank((String) params.get("lastname_s")) + "-----");

        if (StringUtils.isNotBlank((String) params.get("lastname_s"))) {
            System.out.println("执行角色中的用户模糊查询");
            PageUtils page = sysRoleService.queryRoleListPage(params);
            return R.ok().put("page", page);
        }

        return R.ok().put("page", new PageUtils(null, 0, 0, 0));
    }


    /**
     * 文档添加部门权限时  初始化模糊查询
     */
    @RequestMapping("/deptselectlist")
    @RequiresPermissions("sys:sysdocumentdirectoryrights:deptselectlist")
    public R deptselectlist(@RequestParam Map<String, Object> params) {
        System.out.println("模糊条件:" + StringUtils.isNotBlank((String) params.get("lastname_s")) + "-----");

        if (StringUtils.isNotBlank((String) params.get("lastname_s"))) {
            System.out.println("执行角色中的用户模糊查询");
            PageUtils page = sysDeptService.queryDeptListPage(params);
            return R.ok().put("page", page);
        }

        return R.ok().put("page", new PageUtils(null, 0, 0, 0));
    }


}
